package com.apes.framework.plugin.workflow.parser.element;

import com.apes.framework.plugin.filereader.xml.ApesElement;
import com.apes.framework.plugin.filereader.xml.ApesElementParser;
import com.apes.framework.plugin.workflow.parser.model.User;
import com.apes.framework.plugin.workflow.parser.node.WorkflowNodeParser;
import org.springframework.stereotype.Component;

/**
 * 功能：role元素解析器
 *
 * @author xul
 * @create 2018-06-30 11:35
 */
@Component
public class RoleElementParser implements ApesElementParser<ApesElement, User> {
    /**
     * 可解析的元素列表
     **/
    private final String[] elementNames = {"role", "post"};

    /**
     * 功能：可解析的节点或元素列表
     */
    @Override
    public String[] getNames() {
        return elementNames;
    }

    /**
     * 功能：可解析节点域
     */
    @Override
    public String getDomain() {
        return WorkflowNodeParser.domain;
    }

    /**
     * 功能：元素解析
     *
     * @param element
     */
    @Override
    public User parse(ApesElement element) {
        User user = new User();
        user.setName(element.getName().toLowerCase());
        element.getAttributes().forEach((k, v) -> {
            if (k.equalsIgnoreCase("id")) user.setId(v);
            if (k.equalsIgnoreCase("strategy")) user.setStrategy(v);
            if (k.equalsIgnoreCase("type")) user.setType(v);
            if (k.equalsIgnoreCase("remark")) user.setRemark(v);
        });
        return user;
    }
}
